package com.geezdata.cps.sdk3rd.jushita.enums;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.geezdata.cps.base.enums.BaseEnum;
import com.geezdata.cps.base.enums.ErrorCode;
import com.geezdata.cps.base.exceptions.MyException;

public enum OrderStatus implements BaseEnum {
	TRADE_NO_CREATE_PAY(1, "没有创建支付宝交易"),
	WAIT_BUYER_PAY(2, "等待买家付款"),
	SELLER_CONSIGNED_PART(3, "卖家部分发货"),
	WAIT_SELLER_SEND_GOODS(4, "等待卖家发货,即:买家已付款"),
	WAIT_BUYER_CONFIRM_GOODS(5, "等待买家确认收货,即:卖家已发货"),
	TRADE_BUYER_SIGNED(6, "买家已签收,货到付款专用"),
	TRADE_FINISHED(7, "交易成功"),
	TRADE_CLOSED(8, "付款以后用户退款成功，交易自动关闭"),
	TRADE_CLOSED_BY_TAOBAO(9, "付款以前，卖家或买家主动关闭交易"),
	PAY_PENDING(10, "国际信用卡支付付款确认中"),
	WAIT_PRE_AUTH_CONFIRM(11, "0元购合约中");

    private Integer code;
    private String desc;
    
    private static final Logger logger = LoggerFactory.getLogger(OrderStatus.class);

    OrderStatus(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public int getCode() {
        return this.code;
    }

    @Override
    public String getDesc() {
        return this.desc;
    }

    public static OrderStatus getByCode(Integer code) {
        for (OrderStatus orderStatusEnum : values()) {
            if (orderStatusEnum.getCode() == code.intValue()) {
                return orderStatusEnum;
            }
        }
        logger.error("Order status not exists.Code is " + code);
        throw new MyException(ErrorCode.INTERNAL_SERVER_ERROR);
    }
}
